package cn.itcast.solr;

import cn.itcast.pojo.Heiheima;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class SolrIndexCreateTest {

    //增加
    @Test
    public void testCreateIndex() throws IOException, SolrServerException {
        //和solr服务建立连接
        SolrServer server=new HttpSolrServer("http://localhost:8080/solr/core2");

        //创建文档数据
        SolrInputDocument document=new SolrInputDocument();

        document.addField("id","100844");
        document.addField("title","这是测试core2个核心");
        document.addField("price",1212);

        server.add(document);
        server.commit();

    }

    //修改
    @Test
    public void testUpdateIndex() throws IOException, SolrServerException {
        //和solr服务建立连接
        SolrServer server=new HttpSolrServer("http://localhost:8080/solr/core2");

        //创建文档数据
        SolrInputDocument document=new SolrInputDocument();

        document.addField("id","100844");
        document.addField("title","这是测试core2个核心");
        document.addField("price",121212121);

        server.add(document);
        server.commit();

    }

    //pojo操作
    @Test
    public void testCreateIndexWithBean() throws IOException, SolrServerException {
        //和solr服务建立连接
        SolrServer server=new HttpSolrServer("http://localhost:8080/solr/core2");

        Heiheima heiheima=new Heiheima("id","这是用pojo的操作", 35622L);

        server.addBean(heiheima);
        server.commit();

    }


    public void haha(){
        int a=10;
        int b=20;
        System.out.println(a+b);
    }
    public void haha1(){
         int a=10;
        int b=20;
        System.out.println(a+b);
    }
}
